package org.monster.uiboot;

import org.monster.context.util.URIUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * 移除活动
 */
public class RemoveAction extends ItemAction implements ActionListener {


    /**
     * 构造方法
     *
     * @param frame 片段
     */
    public RemoveAction(Frame frame) {
        super(frame);
    }

    /**
     * 活动执行
     *
     * @param e 活动事件
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        jFileChooser.setCurrentDirectory(new File(System
                .getProperty("user.dir") + File.separator + "webapps"));
        jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int selectedVal = jFileChooser.showOpenDialog(frame);
        if (selectedVal == JFileChooser.APPROVE_OPTION) {
            StringBuffer buffer = new StringBuffer();
            buffer.append("{dos-(2)-")
                    .append(URIUtils.endsWithURI(jFileChooser.getSelectedFile()
                            .getPath(), File.separator)).append("}");

            receiver.receive(buffer.toString());
        }
    }
}
